// pages/joincourse/joincourse.js
const app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        sId:'',
        cId:'',
        cname:''
    },

    join(e) {
        console.log(e.currentTarget.dataset.text)
        this.setData({
            cId:e.currentTarget.dataset.text
        })
        let{sId,cId} = this.data;
        let postData = {
            sId:this.data.sId,
            cId:this.data.cId,
        }
        postData = {...this.data}
        postData = {sId,cId}
    
        wx.request({
          url: 'http://localhost/public/course/course/joincouse',
          method: "POST",
          data: postData,
          success: ({data}) => {
            console.log(data);
            console.log(data.status);
            if(data.status === 'success'){
              console.log(data);
              wx.switchTab({
                url: '/pages/course/course',
              })
            }else{
              this.setData({
                warnToast: true,
                message:data.message
              });
              setTimeout(() => {
                this.setData({
                    hidewarnToast: true,
                });
                setTimeout(() => {
                  this.setData({
                      warnToast: false,
                      hidewarnToast: false,
                  });
                }, 300);
              }, 3000);
              console.log(data.message);
            }
          },
          fail:(err)=> {
            console.log(err);
          }
        })
      },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        let courseList = this;
        wx.request({
            url: 'http://localhost/public/course/course/joincouselist',
            data: {},
            header: {'content-type':'application/json'},
            method: "GET",
            success: ({data}) => {
                console.log(data)
                courseList.setData({
                    data:data,
                })
            },
        })
        this.setData({
            sId:app.globalData.userId,
        })
    },

    

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})